package com.克隆02.方式01;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 克隆实现方式一：实现cloneable接口，并重写Object的clone方法:
 * 浅克隆
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Student implements Cloneable{
    private int age;
    private String name;


    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        Student s1 = new Student(1001, "张三");
        Student s2  = (Student) s1.clone();

        System.out.println(s1==s2);//比较内容地址，false，不一样
        s2.setName("李四");
        System.out.println(s1.getName());//张三
        System.out.println(s2.getName());//李四
    }

}
